package com.ict.web.controller.yzq;


import java.io.InputStream;
import java.util.List;

import com.ict.common.utils.poi.ExcelUtil;
import com.ict.web.domain.ExpertInformationSheet;
import com.ict.web.dto.*;
import com.ict.web.service.IExpertInformationSheetService;
import com.ict.web.vo.ExpertInformationSheetListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ict.common.annotation.Log;
import com.ict.common.core.controller.BaseController;
import com.ict.common.core.domain.AjaxResult;
import com.ict.common.enums.BusinessType;
import com.ict.common.core.page.TableDataInfo;

/**
 * 专家库信息Controller
 *
 * @author liujie
 * @date 2022-02-23
 */
@Api(tags = "专家库信息")
@RestController
@RequestMapping("/web/sheet")
public class ExpertInformationSheetController extends BaseController
{
    @Autowired
    private IExpertInformationSheetService expertInformationSheetService;

//    /**
//     * 查询专家库信息列表(根据专家实体来查询)
//     */
//    @ApiOperation("查询(专家实体)专家库信息列表")
//    @GetMapping("/list")
//    public TableDataInfo ExpertListInfo(ExpertInformationSheet expertInformationSheet)
//    {
//        startPage();
//        List<ExpertInformationSheet> list = expertInformationSheetService.selectExpertInformationSheetList(expertInformationSheet);
//        return getDataTable(list);
//    }

    @ApiOperation("查询（查询实体）专家库信息列表")
    @GetMapping("/queryList")
    public TableDataInfo queryList(QueryExpertInformationSheetDto queryDto)
    {
        List<ExpertInformationSheetListVo> list = expertInformationSheetService.selectExpertInfoSheetList(queryDto);
        return getDataTable(list);
    }

    /**
     * 用户id获取专家库信息详细信息
     */
    @ApiOperation("用户id获取专家库信息详细信息")
    @GetMapping(value = "/getInfoByUserId")
    public AjaxResult getInfoByUserId()
    {
        return AjaxResult.success(expertInformationSheetService.getInfoByUserId());
    }

    /**
     * 获取专家库信息详细信息
     */
    @ApiOperation("获取专家库信息详细信息")
    @GetMapping(value = "/{expertId}")
    public AjaxResult getInfo(@PathVariable("expertId") Long expertId)
    {
        return AjaxResult.success(expertInformationSheetService.selectExpertInformationSheetByExpertId(expertId));
    }

    @ApiOperation("专家导入")
    @Log(title = "专家信息导入" ,businessType = BusinessType.IMPORT)
    @PostMapping("/import")
    public void importExpert(InputStream input) throws Exception {
        ExcelUtil<ExpertInformationSheet> util = new ExcelUtil<>(ExpertInformationSheet.class);
        util.importExcel("专家信息数据",input,5);
    }
    /**
     * 新增专家库信息
     */
    @ApiOperation("新增专家库信息")
    @Log(title = "专家库信息", businessType = BusinessType.INSERT)
    @PostMapping("/addSave")
    public AjaxResult add(@RequestBody InsertExpertInformationSheetDto dto) throws Exception {
          return AjaxResult.success(expertInformationSheetService.insertExpertInformationSheet(dto));
    }

    /**
     * 修改专家库信息
     */
    @ApiOperation("修改专家库信息")
    @Log(title = "专家库信息", businessType = BusinessType.UPDATE)
    @PutMapping("/editSave")
    public AjaxResult edit(@RequestBody UpdateExpertInformationSheetDto dto)
    {
        return toAjax(expertInformationSheetService.updateExpertInformationSheet(dto));
    }

    /**
     * 删除专家库信息
     */
    @ApiOperation("删除专家库信息")
    @Log(title = "专家库信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{expertId}")
    public AjaxResult remove(@PathVariable Long expertId) {
        return toAjax(expertInformationSheetService.deleteExpertInformationSheetByExpertId(expertId));
    }

    @ApiOperation("专家抽取-条件查询")
    @GetMapping("/conditionSelect")
    public TableDataInfo conditionSelect(ExpertInformationSheetDto dto)
    {
        startPage();
        List<Long> list = expertInformationSheetService.conditionSelect(dto,null);
        return getDataTable(list);
    }
}
